package com.feichuang.chineseWoodCarving.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.feichuang.chineseWoodCarving.model.MUser;

public class LoginHandlerInterceptor extends HandlerInterceptorAdapter {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        MUser userInfo = (MUser) request.getSession().getAttribute("LoginStaff");
        return true;
        /*
         * if (request.getServletPath().startsWith("/indexCon") || request.getServletPath().startsWith("/Error") || request.getServletPath().startsWith("/Content") ||
         * request.getServletPath().startsWith("/i18n")) { return true; }
         * 
         * if (null != userInfo) { return true; }
         * 
         * response.sendRedirect(request.getContextPath()); return false;
         */
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        // 看能不能 记录uiAcc
        try {
            // TrackIdManager trackIdManager = new TrackIdManager();
            // VMUser userInfo = (VMUser) request.getSession().getAttribute("LoginStaff");
            // if (null != userInfo) {
            // trackIdManager.createTrackId(userInfo.getUserNo());
            // } else {
            // trackIdManager.createTrackId("pt");
            // }
            // LogBusiness logBusiness = new LogBusiness();
            // MLogUiacc uiacc = new MLogUiacc();
            // uiacc.setModule("网站系统");
            // uiacc.setUserIP(request.getRemoteAddr());
            // uiacc.setKeyMessage("系统：" + " 用户" + uiacc.getUserIP());
            // logBusiness.writeUiAccLog(uiacc);
        } catch (Exception e) {

        }
    }
}
